//
//  NewsFromTableViewCell.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/13.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "NewsFromTableViewCell.h"

@implementation NewsFromTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self.contentView addSubview:self.userHead]; // 用户头像
        [self.contentView addSubview:self.userName]; // 用户名称
        [self.contentView addSubview:self.userNews]; // 用户消息
        [self.contentView addSubview:self.timeLab]; // 时间标签
        [self.contentView addSubview:self.isRead]; // 是否已读
        [self showNewsCell];
    }
    return self;
}

- (void)showNewsCell
{
    _userHead.sd_layout
    .topSpaceToView(self.contentView,kHeightScale(10))
    .leftSpaceToView(self.contentView,kWidthScale(10))
    .widthIs(kWidthScale(62))
    .heightIs(kHeightScale(62));
    
    _userName.sd_layout
    .topSpaceToView(self.contentView,kHeightScale(21))
    .leftSpaceToView(self.userHead,kWidthScale(10))
    .widthIs(kWidthScale(100))
    .heightIs(kHeightScale(15));
    
    _isRead.sd_layout
    .centerYEqualToView(self.userHead)
    .rightSpaceToView(self.contentView,kWidthScale(10))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(31));
    
    _timeLab.sd_layout
    .topEqualToView(self.userHead)
    .rightSpaceToView(self.isRead,kWidthScale(10))
    .widthIs(kWidthScale(70))
    .heightIs(kHeightScale(15));
    
    _userNews.sd_layout
    .topSpaceToView(self.userName,kHeightScale(9))
    .leftEqualToView(self.userName)
    .rightEqualToView(self.timeLab)
    .heightIs(kHeightScale(11));
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 用户头像
- (UIButton *)userHead
{
    if (!_userHead)
    {
        _userHead = [UIButton buttonWithType:UIButtonTypeCustom];
        [_userHead setImage:[UIImage imageNamed:@"toixiang"] forState:0];
        _userHead.imageEdgeInsets = UIEdgeInsetsMake(3, 3, 3, 3);
        _userHead.layer.shadowColor = [UIColor blackColor].CGColor;
        _userHead.layer.shadowOffset = CGSizeMake(0, 5);
        _userHead.layer.shadowOpacity = 0.5;
        _userHead.layer.shadowRadius = 6.0;
        _userHead.layer.cornerRadius = 6.0;
        _userHead.clipsToBounds = NO;
    }
    return _userHead;
}
// 用户名称
- (UILabel *)userName
{
    if (!_userName)
    {
        _userName = [[UILabel alloc] init];
        _userName.text = @"迪丽热巴";
    }
    return _userName;
}
// 用户消息
- (UILabel *)userNews
{
    if (!_userNews)
    {
        _userNews = [[UILabel alloc] init];
        _userNews.textColor = [UIColor lightGrayColor];
        _userNews.text = @"你喜欢迪丽热巴么？我很喜欢她。非常喜欢她";
        _userNews.font = FONT(12);
    }
    return _userNews;
}
// 时间标签
- (UILabel *)timeLab
{
    if (!_timeLab)
    {
        _timeLab = [[UILabel alloc] init];
        _timeLab.text = @"1小时前";
        _timeLab.textAlignment = NSTextAlignmentRight;
        _timeLab.font = FONT(12);
    }
    return _timeLab;
}
// 是否已读
- (UIImageView *)isRead
{
    if (!_isRead)
    {
        _isRead = [[UIImageView alloc] init];
        _isRead.image = [UIImage imageNamed:@"weidu"];
//        [_isRead setBackgroundImage:[UIImage imageNamed:@"weidu"] forState:UIControlStateNormal];
//        [_isRead setBackgroundImage:[UIImage imageNamed:@"yidu"] forState:UIControlStateSelected];
    }
    return _isRead;
}

@end
